﻿#region

using System;
using System.Messaging;

#endregion

namespace NsbMonitorClientService.QueueManager
{
    public class FetchQueueStatus : IFetchQueueStatus
    {
        private readonly ICountMessagesInQueue _countMessagesInQueue;
        private readonly IFetchOldestMessageTime _fetchOldestMessageTime;

        public FetchQueueStatus(ICountMessagesInQueue countMessagesInQueue, IFetchOldestMessageTime fetchOldestMessageTime)
        {
            _countMessagesInQueue = countMessagesInQueue;
            _fetchOldestMessageTime = fetchOldestMessageTime;
        }

        public QueueStatus QueueStatus(MessageQueue messageQueue)
        {
            int count = _countMessagesInQueue.CountMessages(messageQueue);
            DateTime? oldestMessageTime = _fetchOldestMessageTime.OldestMessageTime(messageQueue);

            return new QueueStatus(count, oldestMessageTime);
        }
    }
}